<?php
/*********************************************************************\
* This File is a part of BH-PANEL (Breizh-Heberg Panel v2.1)
* Copyright (C) 2008-2009 the BH Developpers : Vincent Giersch <mail@vincordi.fr>, Cyprien Laleau <fanning.fr@gmail.com> and Edwin Cabiten <marmottes44@hotmail.fr>
* See file AUTHORS to get more informations

* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.

* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.

* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
/*********************************************************************/


class bh_doms_gest {
	private $login = "gv3731-ovh";
	private $password = "";
	private $test = true;
	private $session;
	private $soap;
	
	public function __construct() {
		$this->soap = new SoapClient('http://www.ovh.com/soapi/ovh.wsdl');
		try {
			$this->session = $this->soap->login($this->login,$this->password,null);
		}
		catch(SoapFault $fault) {
			$this->error("OVH Servers Connexion Error");
		}
	}	
	
	private function error($error) {
		$tpl = new gagatemplate('');
		$tpl->assign(array('fault' => $error));
		$tpl->parse('global-soaperror.html');
		exit();
	}
	
	public function deconnect() {
		$this->soap->logout($this->session);
	}
	
	public function infos_dom($domaine) {
		try {
			$dom_infos = $this->soap->domainInfo($this->session, $domaine);
		}
		catch(SoapFault $fault) {
			$this->error($fault);
		}
		
		// DNS
		$return_infos['dns'][1] = $dom_infos->dns['0']->name;
		$return_infos['dns'][2] = $dom_infos->dns['1']->name;
		$return_infos['dns'][3] = $dom_infos->dns['2']->name;
		$return_infos['dns'][4] = $dom_infos->dns['3']->name;
		// Create
		$create = explode('-', $dom_infos->creation);
		$return_infos['date']['create'] = $create['2'].'/'.$create['1'].'/'.$create['0'];
		// Expire
		$expire = explode('-', $dom_infos->expiration);
		$return_infos['date']['expire'] = $expire['2'].'/'.$expire['1'].'/'.$expire['0'];
		return $return_infos;
	}
	
	public function create_dom($array_infos) {
	/* Structure de l'array :
		nom
		prenom
		email
		password
		tel
		adresse
		ville
		code postal
		pays (FR)
		---------------------
	    return nic_id
	*/
	}
	
	public function dom_dispo($domaine) {
		try {
			$this->soap->domainCheck($this->session, $domaine);
		}
		catch(SoapFault $fault) {
			$this->error($fault);
		}
		
		if($dispo[0]->value == 1) {
			return 1;
		}
		else {
			return 2;
		}
		
	}
	
	public function dom_lock($domaine) {
		try {
			$this->soap->domainLock($this->session, $domaine);
		}
		catch(SoapFault $fault) {
			$this->error($fault);
		}
		
	}
	
	public function dom_unlock($domaine) {
		try {
			$this->soap->domainUnlock($this->session, $domaine);
		}
		catch(SoapFault $fault) {
			$this->error($fault);
		}
		
	}
	
	public function dom_dns_update($domaine, $dns1, $dns2, $dns3, $dns4, $dns5){
		try {
			$this->soap->domainDnsUpdate($this->session, $domaine, $dns1, $dns2, $dns3, $dns4, $dns5, '', '', '', '', '');
		}
		catch(SoapFault $fault) {
			$this->error($fault);
		}	
	}	
}

?>